using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.BLL;

public partial class crm_questionnaire_questpart_QuestPartlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            quniare_list.HRef = "../QuestionnaireModify.aspx?cur_page=" + Request.Params["cur_page"] + "&qtype=2&QunaireID=" + Request.Params["QunaireID"];
            preview.HRef = "QuestionnaireView.aspx?cur_page=" + Request.Params["cur_page"] + "&qtype=2&QunaireID=" + Request.Params["QunaireID"];
            add_url.HRef = "QuestPartAdd.aspx?QunaireID=" + Request.Params["QunaireID"];
            hfquestid.Value = Request.Params["QunaireID"].ToString();
            if (Request.Params["cur_page"] != null)
            {
                hfcur_page.Value = Request.Params["cur_page"].ToString();
            }
            else
            {
                hfcur_page.Value = "0"; 
            }
            initial(Int32.Parse(hfquestid.Value));
        }
    }

    void initial(int qur_id)
    {
        Questionnaire qq = new Questionnaire();
        IList qqlist = qq.getQPartList(qur_id);
        
        GridView1.DataSource = qqlist;
        GridView1.DataBind();
    }

    protected void DoEdit(object sender, System.EventArgs e)
    {
        string QUP_ID = ((LinkButton)sender).CommandArgument.ToString();
        Response.Redirect("QuestPartModify.aspx?cur_page="+hfcur_page.Value+"&questid="+hfquestid.Value+"&QUP_ID=" + QUP_ID);
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (-2 == e.NewPageIndex)
        {
            TextBox txtNewPageIndex = null;
            GridViewRow pagerRow = theGrid.BottomPagerRow;
            if (null != pagerRow)
            {
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (null != txtNewPageIndex)
            {
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            newPageIndex = e.NewPageIndex;
        }

        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
        theGrid.PageIndex = newPageIndex;
        initial(Int32.Parse(hfquestid.Value));
    }

    protected void DoDelete(object sender, System.EventArgs e)
    {
        //string DDR_ID = ((LinkButton)sender).CommandArgument.ToString();
        //DDRController iCon = new DDRController();

        //if (iCon.DeleteDDR(Int32.Parse(DDR_ID)))
        //{
        //    ShowDataBind();
        //}
    }
}
